﻿Class Application

    Private Sub Application_DispatcherUnhandledException(sender As Object, e As System.Windows.Threading.DispatcherUnhandledExceptionEventArgs) Handles Me.DispatcherUnhandledException

        If MessageBox.Show("发生错误，是否保存设置？", "错误", MessageBoxButton.YesNo, MessageBoxImage.Error) = MessageBoxResult.Yes Then
            Try
                My.Settings.Settings = Settings.Settings.Default.ClassToString
                My.Settings.Save()
            Catch ex As Exception

            End Try
        End If
#If DEBUG Then
        If e.Exception IsNot Nothing Then
            MessageBox.Show(e.Exception.ToString, "错误信息", MessageBoxButton.OK)
        End If

#End If
        e.Handled = True
        Application.Current.Shutdown()
    End Sub

    ' 应用程序级事件(例如 Startup、Exit 和 DispatcherUnhandledException)
    ' 可以在此文件中进行处理。

    Private Sub Application_Exit(ByVal sender As Object, ByVal e As System.Windows.ExitEventArgs) Handles Me.Exit
        My.Settings.Settings = Settings.Settings.Default.ClassToString
        My.Settings.Save()
    End Sub
End Class
